#region Using Statements

using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;


#endregion

namespace _1942
{
    /// <summary>
    /// This is a game component that implements Power Source Element.
    /// </summary>
    public class PowerUp : Sprite
    {
        #region Variables

        protected Texture2D texture;
        protected Random random;

        //Window size
        private static int windowHeight = -1;
        private static int windowWidth = -1;

        #endregion

        #region Constructors

        public PowerUp(Game game, ref Texture2D theTexture)
            : base(game, ref theTexture)
        {
            //Sets the window size
            if (windowHeight == -1)
            {
                windowHeight = Game.Window.ClientBounds.Height;
                windowWidth = Game.Window.ClientBounds.Width;
            }

            texture = theTexture;

            Frames = new List<Rectangle>();

            Rectangle frame = new Rectangle(698,203,32,32);

            Frames.Add(frame);

            frame.X = 731;
            Frames.Add(frame);

            frame.X = 764;
            Frames.Add(frame);

            frameDelay = 100;

            // Initialize the random number generator and put the power source in your
            // start position
            random = new Random(GetHashCode());

            PutinStartPosition();
        }

        #endregion

        #region Methods

        /// <summary>
        /// Initialize Position and Velocity
        /// </summary>
        public void PutinStartPosition()
        {
            Position = new Vector2(
                 random.Next(windowWidth - currentFrame.Width),
                 -40);

            Enabled = false;
        }

        public override void Update(GameTime gameTime)
        {
            // Check if the still visible
            if (Position.Y >= windowHeight)
            {
                PutinStartPosition();
            }

            // Move
            Position = new Vector2(Position.X, Position.Y + 1);

            base.Update(gameTime);
        }

        /// <summary>
        /// Check if the object intersects with the specified rectangle
        /// </summary>
        /// <param name="rect">test rectangle</param>
        /// <returns>true, if has a collision</returns>
        public bool CheckCollision(Rectangle rect)
        {
            return this.getRect.Intersects(rect);
        }

        #endregion
    }
}